package com.lyf.shop.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.lyf.common.core.domain.R;
import com.lyf.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lyf.common.log.annotation.Log;
import com.lyf.common.log.enums.BusinessType;
import com.lyf.common.security.annotation.RequiresPermissions;
import com.lyf.shop.domain.Number;
import com.lyf.shop.service.INumberService;
import com.lyf.common.core.web.controller.BaseController;
import com.lyf.common.core.web.domain.AjaxResult;
import com.lyf.common.core.utils.poi.ExcelUtil;
import com.lyf.common.core.web.page.TableDataInfo;

/**
 * 会员Controller
 * 
 * @author lyf
 * @date 2023-04-08
 */
@RestController
@RequestMapping("/number")
public class NumberController extends BaseController
{
    @Autowired
    private INumberService numberService;

    /**
     * 查询会员列表
     */
    @RequiresPermissions("shop:number:list")
    @GetMapping("/list")
    public TableDataInfo list(Number number)
    {
        startPage();
        List<Number> list = numberService.selectNumberList(number);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @RequiresPermissions("shop:number:export")
    @Log(title = "会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Number number)
    {
        List<Number> list = numberService.selectNumberList(number);
        ExcelUtil<Number> util = new ExcelUtil<Number>(Number.class);
        util.exportExcel(response, list, "会员数据");
    }

    /**
     * 获取会员详细信息
     */
    @RequiresPermissions("shop:number:query")
    @GetMapping(value = "/{numberId}")
    public AjaxResult getInfo(@PathVariable("numberId") Long numberId)
    {
        return success(numberService.selectNumberByNumberId(numberId));
    }

    /**
     * 新增会员
     */
    @RequiresPermissions("shop:number:add")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Number number)
    {
        return toAjax(numberService.insertNumber(number));
    }

    /**
     * 修改会员
     */
    @RequiresPermissions("shop:number:edit")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Number number)
    {
        return toAjax(numberService.updateNumber(number));
    }

    /**
     * 删除会员
     */
    @RequiresPermissions("shop:number:remove")
    @Log(title = "会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{numberIds}")
    public AjaxResult remove(@PathVariable Long[] numberIds)
    {
        return toAjax(numberService.deleteNumberByNumberIds(numberIds));
    }


    @InnerAuth
    @GetMapping("/updateDay")
    public R<Boolean> updateByDay(){
        return R.ok(numberService.updateByDay());
    }
}
